package com.xkcyy.study.spring.s01_transaction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * TransService
 *
 * @author yuand
 * @date 2021/5/25
 **/
@Service
public class TransService {


    JdbcTemplate jdbcTemplate;


    @Transactional(rollbackFor = Exception.class)
    public void testTrans() {
        createTable();
        jdbcTemplate.update("insert into tt_user values (1,'11')");

    }

    public void createTable() {
        jdbcTemplate.update(
                "Create Table If Not Exists tt_user(\n" +
                        "\tid int primary key,\n" +
                        "\tname varchar(200)\n" +
                        ")");
    }
}
